﻿/*
	Copyright (c) 2013-2015 EasyDarwin.ORG.  All rights reserved.
	Github: https://github.com/EasyDarwin
	WEChat: EasyDarwin
	Website: http://www.easydarwin.org
*/
#include "EasyBuff.h"

int __EASY_MALLOC_MEMORY(EASY_BUFF_T *pEasyBuff, int bufsize)
{
    if (NULL == pEasyBuff)      return -1;
    if (bufsize < 1)            return -1;

    if (NULL == pEasyBuff->pbuf)
    {
        pEasyBuff->pbuf = (char *) malloc(bufsize);
        if (NULL == pEasyBuff->pbuf)        return -2;

        pEasyBuff->bufsize = bufsize;
    }
    memset(pEasyBuff->pbuf, 0x00, pEasyBuff->bufsize);
    pEasyBuff->bufpos = 0;

    return 0;
}


int __EASY_FREE_MEMORY(EASY_BUFF_T *pEasyBuff)
{
    if (NULL == pEasyBuff)      return -1;

    if (NULL != pEasyBuff->pbuf)
    {
        free(pEasyBuff->pbuf);
        pEasyBuff->pbuf = NULL;
    }

    pEasyBuff->bufpos = 0;
    pEasyBuff->bufsize = 0;

    return 0;
}
